package com.jdew.thkj.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jdew.thkj.R;
import com.jdew.thkj.bean.LiangHaoBean;
import com.jdew.thkj.bean.RisingRecordBean;

import java.text.DecimalFormat;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by yangyang on 2017/9/18.
 */

public class BeautifulNumberAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<LiangHaoBean.DataBean> dataList;
    private LayoutInflater layoutInflater;
    private Context context;
    private View itemView;

    public BeautifulNumberAdapter(Context context, List<LiangHaoBean.DataBean> dataList) {
        this.context = context;
        this.dataList = dataList;
        layoutInflater = LayoutInflater.from(context);
    }

    public void setDataList(List<LiangHaoBean.DataBean> dataList) {
        this.dataList = dataList;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        itemView = layoutInflater.inflate(R.layout.beautiful_number_item, parent, false);
        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MyViewHolder myviewHolder = (MyViewHolder) holder;
        myviewHolder.BindView(holder, position);
        myviewHolder.itemView.setTag(position);
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.num)
        TextView num;
        @Bind(R.id.jiner)
        TextView jiner;
        @Bind(R.id.beautiful_num)
        TextView beautiful_num;
        @Bind(R.id.time)
        TextView time;

        MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        public void BindView(RecyclerView.ViewHolder holder, int position) {
             DecimalFormat df = new DecimalFormat("0.00");
            ((MyViewHolder) holder).num.setText(dataList.get(position).getUserPhone());
            ((MyViewHolder) holder).jiner.setText(df.format(Double.parseDouble(dataList.get(position).getAmount())));
            ((MyViewHolder) holder).time.setText(dataList.get(position).getCreateTime());
            ((MyViewHolder) holder).beautiful_num.setText("靓号:"+dataList.get(position).getUserCode());
        }
    }
}

